using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAL;
using Utility;

namespace BUS
{
    public class MATHANG_BUS
    {
        public static int insert(MatHang_DTO Mhang)
        {
            MATHANG_DAL Mhangdal = new MATHANG_DAL();
          return  Mhangdal.insert(Mhang);
        }
        public static void update(MatHang_DTO Mhang)
        {
            MATHANG_DAL Mhangdal = new MATHANG_DAL();
            Mhangdal.update(Mhang);
        }
        public static void updatemota(MatHang_DTO Mhang)
        {
            MATHANG_DAL Mhangdal = new MATHANG_DAL();
            Mhangdal.updatemota(Mhang);

        }
        public static void updatetinhtranghethan(MatHang_DTO Mhang)
        {
            MATHANG_DAL Mhangdal = new MATHANG_DAL();
            Mhangdal.updateTINHTRANGHETHAN(Mhang);


        }
        public static void updatesoluongphieu(MatHang_DTO Mhang)
        {

            MATHANG_DAL Mhangdal = new MATHANG_DAL();
            Mhangdal.updateSOLUONGMATHANG(Mhang);

        }
        public static void delete(int Mahang)
        {
            MATHANG_DAL Mhangdal = new MATHANG_DAL();
            Mhangdal.delete(Mahang);
        }
        
        public static MatHangColection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {

            MATHANG_DAL Mhangdal = new MATHANG_DAL();
            return Mhangdal.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        //public static MatHangColection Getmathang_conhan(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        //{
        //    Criteria cri = new Criteria();
        //    TimeSpan r = DateTime.Parse(MatHangColumns.ThoiGian_KetThuc) - DateTime.Parse(MatHangColumns.ThoiGian_BatDau);
        //    cri.add(Condition.AND, r.TotalSeconds.ToString(), Condition.GREATER_THAN, 0);
        //    MATHANG_DAL Mhangdal = new MATHANG_DAL();

        //    return Mhangdal.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        //}
        public static MatHangColection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            MATHANG_DAL Mhangdal = new MATHANG_DAL();
            return Mhangdal.Get(cri.Criter, 0, 0, MatHangColumns.MaMH.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static MatHang_DTO GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, MatHangColumns.MaMH.ToString(), Condition.EQUAL, iD);
            MATHANG_DAL Mhangdal = new MATHANG_DAL();
            MatHangColection Mhangcltion = Mhangdal.Get(cri.Criter, 0, 0, MatHangColumns.MaMH.ToString(), OrderDirection.ASC.ToString(), out total);
            if (Mhangcltion.Count > 0)
                return Mhangcltion[0];
            return null;

        }
        


    }
}
